package com.cz.nongyetongv5.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.activity.EntDetailActivity;
import com.cz.nongyetongv5.activity.MapViewActivity;


public class EntInfoOperateNzdFragment extends Fragment {
    private TextView tv_capital;
    private TextView tv_business_license;
    private TextView tv_operating_license;
    private TextView tv_addr;
    private View view;
    private ImageView iv_map;

    public static EntInfoOperateNzdFragment newInstance() {
        EntInfoOperateNzdFragment fragment = new EntInfoOperateNzdFragment();
        return fragment;
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_ent_info_operate_nzd, null);
        tv_capital = view.findViewById(R.id.tv_capital);
        tv_business_license = view.findViewById(R.id.tv_business_license);
        tv_operating_license = view.findViewById(R.id.tv_operating_license);
        tv_addr = view.findViewById(R.id.tv_addr);
        iv_map = view.findViewById(R.id.iv_map);
        iv_map.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (((EntDetailActivity) getActivity()).getEntBean().getLatitude() == null || ((EntDetailActivity) getActivity()).getEntBean().getLatitude() == 0f) {
                    Toast.makeText(getActivity(),"暂无坐标信息",Toast.LENGTH_SHORT).show();
                } else {
                    Intent intent = new Intent(getActivity(), MapViewActivity.class);
                    intent.putExtra("latitude", ((EntDetailActivity) getActivity()).getEntBean().getLatitude());
                    intent.putExtra("longitude", ((EntDetailActivity) getActivity()).getEntBean().getLongitude());
                    startActivity(intent);
                }
            }
        });

        init();
        return view;
    }


    public void init() {
        if (((EntDetailActivity) getActivity()).getEntBean().getCapital() != null) {
            tv_capital.setText(((EntDetailActivity) getActivity()).getEntBean().getCapital());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getBusiness_license() != null) {
            tv_business_license.setText(((EntDetailActivity) getActivity()).getEntBean().getBusiness_license());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getOperating_license() != null) {
            tv_operating_license.setText(((EntDetailActivity) getActivity()).getEntBean().getOperating_license());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getAddress() != null) {
            tv_addr.setText(((EntDetailActivity) getActivity()).getEntBean().getAddress());
        }
    }


    //    @OnClick(R.id.iv_map)
    //    public void toMap(ImageView imageView) {
    //        if (((EntDetailActivity) getActivity()).getEntBean().getLatitude() == null || ((EntDetailActivity) getActivity()).getEntBean().getLatitude() == 0f) {
    //            ToastUtils.showToast(getActivity(), "暂无坐标信息");
    //        } else {
    //            Intent intent = new Intent(getActivity(), MapViewActivity.class);
    //            intent.putExtra("latitude", ((EntDetailActivity) getActivity()).getEntBean().getLatitude());
    //            intent.putExtra("longitude", ((EntDetailActivity) getActivity()).getEntBean().getLongitude());
    //            intent.putExtra("addr", ((EntDetailActivity) getActivity()).getEntBean().getAddress());
    //            startActivity(intent);
    //        }
    //    }
}